package GUIadapter;

import java.util.List;

import javax.swing.table.AbstractTableModel;

import ModelLayer.Supplier;

@SuppressWarnings("serial")
public class TableSupplierAdapterModel extends AbstractTableModel
{
	private final String[] columnHeader= {"Index",
			                                  "Company",
			                                  "Contact person",
			                                  "Address",
			                                  "Postal/Zip",
			                                  "City",
			                                  "E-mail",
			                                  "Phone",
			                                  "Creditor number"};
	
	private List<Supplier> supplierList;

	public TableSupplierAdapterModel(List<Supplier> supplierList)
	{
		this.supplierList = supplierList;
	}
	
	@Override
	public String getColumnName(int column)
	{
		// TODO Auto-generated method stub
		return columnHeader[column];
	}

	@Override
	public int getColumnCount()
	{
		// TODO Auto-generated method stub
		return columnHeader.length; //depends on amount of getters for a supplier eg.: "getName()"... very ugly
	}

	@Override
	public int getRowCount()
	{
		// TODO Auto-generated method stub
		return supplierList.size();
	}

	@Override
	public Object getValueAt(int row, int col)
	{
		// TODO Auto-generated method stub
		Supplier supplier = supplierList.get(row);
		switch(col)
		{
		case 0:
			return new Integer(row);//index
		case 1:
			return supplier.getCompanyName();
		case 2:
			return supplier.getName();
		case 3:
			return supplier.getAddress();
		case 4:
			return supplier.getPostal();
		case 5:
			return supplier.getCity();
		case 6:
			return supplier.getEmail();
		case 7:
			return supplier.getPhone();
		case 8:
			return new Integer(supplier.getCreditornr());
		}
		return null; //should never reach here..!
	}

	
} //end TableSupplierAdapter
